Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i18n lib change - use htmr to parse html inside json files #8585 #8592

Merged
merged 2 commits into from
Nov 24, 2022

Conversation

pettinarip
Copy link
Member

@pettinarip pettinarip commented Nov 14, 2022

This PR removes the usage of dangerouslySetInnerHTML (for security reasons) to insert html content from the translation files. Instead, it uses the htmr lib where we can also use our own custom components (similar to what we do with markdown files).

Description

  • Revert the usage of dangerouslySetInnerHTML
  • Use htmr to parse the inner html that json files may have
  • Use our own custom components in the parsing process

Related Issue

#8345

@github-actions github-actions bot added content 🖋️ This involves copy additions or edits dependencies 📦 Changes related to project dependencies review needed 👀 labels Nov 14, 2022
@pettinarip pettinarip changed the title use htmr to parse html inside json files i18n lib change - use htmr to parse html inside json files #8585 Nov 14, 2022
@gatsby-cloud
Copy link

gatsby-cloud bot commented Nov 15, 2022

✅ ethereum-org-website-react-i18n deploy preview ready

@pettinarip
Copy link
Member Author

@pettinarip pettinarip mentioned this pull request Nov 17, 2022
const transform = {
a: Link,
}

// Wrapper on <FormattedHTMLMessage /> to always fallback to English
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems this explanation is now out of date (given we swapped i18n libs)? Does it still fallback to English?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. Yea, I'll update that comment. And yes, it fallback to English.

Copy link
Member Author

@pettinarip pettinarip Nov 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, in const { t } = useTranslation(), the t function is the one that fallback to English.

id: string
}

const transform = {
a: Link,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the only element we'd want a custom component for?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So far I haven't seen any other html element on the translation files where we would want to use a custom React component.

Copy link
Member

@samajammin samajammin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple small questions but overall this seems like a much cleaner way to accomplish this!

@pettinarip pettinarip marked this pull request as draft November 22, 2022 13:34
@pettinarip pettinarip marked this pull request as ready for review November 23, 2022 15:23
@corwintines corwintines merged commit e90d693 into react-i18next Nov 24, 2022
@corwintines corwintines deleted the i18n-parse-html-json branch November 24, 2022 20:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
content 🖋️ This involves copy additions or edits dependencies 📦 Changes related to project dependencies
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants